import { getListTask, updateState } from "@/api/task/list.js";
import { resetObject, downloadFile } from "@/utils/common";
import dayjs from "dayjs";
export default {
  data() {
    return {
      requestFunc: getListTask,
      searchParams: {
        TaskNum: "",
        CandidateName: "",
        ParmTaskStateId: null,
        ParmTaskProgressId:
          this.$route.query && this.$route.query.p
            ? this.$route.query.p + ""
            : ""
      },
      tableData: []
    };
  },
  methods: {
    updateState(TaskId, State) {
      let tip;
      if (State === 287) {
        tip = "确定修改状态，是否撤销？";
      }
      if (State === 284) {
        tip = "确定修改状态，是否恢复？";
      }
      if (State === 286) {
        tip = "确定修改状态，是否暂停？";
      }
      this.$confirm(tip, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          //287撤销，656暂停
          updateState({ TaskId, State })
            .then(() => {
              this.$message("状态修改成功");
              this.refresh();
            })
            .catch(() => {});
        })
        .catch(() => {});
    },
    returnData(pageList) {
      this.tableData = pageList.data;
    },
    clearSearchParams() {
      resetObject(this.searchParams);
      this.refresh();
    },
    refresh() {
      this.dataTime = dayjs().format("YYYY/MM/DD HH:mm:ss");
      this.$refs.pagination.Refresh();
    },
    filterParams(p) {
      if (
        p.hasOwnProperty("ParmTaskStateId") &&
        (p.ParmTaskStateId === null || p.ParmTaskStateId === "")
      ) {
        p.ParmTaskStateId = 0;
      }
      if (
        p.hasOwnProperty("ParmTaskProgressId") &&
        (p.ParmTaskProgressId === null || p.ParmTaskProgressId === "")
      ) {
        p.ParmTaskProgressId = 0;
      }
      return p;
    },
    surveyReportPdf(no) {
      downloadFile(no);
    }
  }
};
